<template>
  <div class="add">
    <BaseDialog
      :title="$t('审批')"
      width="600px"
      v-model:visible="innerVisible"
      :renderDefaultFooter="false"
    >
      <MyForm
        v-model:formData="formData"
        v-model:columns="formColumns"
        :rules="rules"
        :labelWidth="120"
        :saveBtnLoading="saveBtnLoading"
        background="#fff"
        @submit="onSubmit"
        @cancel="innerVisible = false"
      >
      </MyForm>
    </BaseDialog>
  </div>
</template>
<script setup>
import { ref, computed, onMounted, watch } from "vue";
import * as api from "@/api/index.js";
import { week, currentWeek } from "@/static/week.js";
import { columnFilters } from "@/utils/mUtils.js";
import i18n from "@/lang/index.js";
import { ElMessage } from "element-plus";
const props = defineProps({
  visible: {
    type: Boolean,
  },
  currRow: {
    type: Object,
    default: () => null,
  },
});
const emits = defineEmits(["update:visible", "onSubmit"]);
const innerVisible = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emits("update:visible", val);
  },
});
const formData = ref({
  auditStatus: 1,
});
const formColumns = ref([
  {
    title: "",
    structure: [
      {
        formLayout: "el-row",
        content: [
          {
            label: "是否通过",
            prop: "auditStatus",
            type: "label_radio",
            props: {
              value: "value",
              label: "label",
            },
            options: [
              {
                label: "审核通过",
                value: 1,
              },
              {
                label: "审核驳回",
                value: 2,
              },
            ],
            span: 24,
          },
          {
            label: "审核描述",
            prop: "auditDesc",
            inputType: "textarea",
            type: "label_input",
            span: 24,
          },
        ],
      },
    ],
  },
]);
const rules = ref({
  auditStatus: [{ required: true, message: "请选择是否通过", trigger: "blur" }],
});
const saveBtnLoading = ref(false);
onMounted(() => {});
const onSubmit = () => {
  const parmas = {
    ...formData.value,
    customerId: props.currRow.id,
  };

  saveBtnLoading.value = true;
  api.default.common.customers
    .audit(parmas)
    .then(() => {
      ElMessage.success("审批成功");
      innerVisible.value = false;
      saveBtnLoading.value = false;
      emits("onSubmit");
    })
    .catch(() => {
      saveBtnLoading.value = false;
    });
};
</script>
<style lang="scss" scoped>
.search-btn {
  width: 120px;
  margin: 20px auto 0;
}
</style>
